package com.zx.map.dao.impl;

import com.zx.map.dao.SessionInfoDao;
import com.zx.map.dao.mapper.SessionInfoMapper;
import com.zx.map.dao.model.SessionInfo;
import com.zx.map.dao.model.SessionInfoExample;
import com.zx.platform.dao.mapper.SequenceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 14-3-1
 * Time: 上午10:54
 * To change this template use File | Settings | File Templates.
 */
@Component("sessionInfoDao")
public class SessionInfoImpl implements SessionInfoDao {

    @Autowired
    private SessionInfoMapper mapper;

    @Autowired
    private SequenceMapper sequencemapper;

    /**
     * 新增
     */
    public String add(SessionInfo sessionInfo) throws DataAccessException {
    	sessionInfo.setCreateDate(new Date());
        int column = mapper.insert(sessionInfo);
        if (column != 1) {
            throw new RuntimeException("");
        }
        return sessionInfo.getSessionId();
    }

    /**
     * 修改
     * @param sessionInfo
     * @return
     * @throws org.springframework.dao.DataAccessException
     */
    public String update(SessionInfo sessionInfo) throws DataAccessException {
        int column = mapper.updateByPrimaryKeySelective(sessionInfo);
        if (column != 1) {
            throw new RuntimeException("");
        }
        return sessionInfo.getSessionId();
    }

    /**
     * 删除
     */
    public void delete(SessionInfo sessionInfo) throws DataAccessException {
        int column = mapper.deleteByPrimaryKey(sessionInfo.getSessionId());
        if (column != 1) {
            throw new RuntimeException("");
        }
    }
    
    /**
     * 删除
     */
    public void deleteByExample(SessionInfoExample example) throws DataAccessException {
         mapper.deleteByExample(example);
    }

	/**
	 * 
	 */
	public List<SessionInfo> getListByExample(SessionInfoExample example)
			throws DataAccessException {
		return mapper.selectByExample(example); 
	}
}
